package com.smc.dao.impl;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.smc.dao.MessageDao;
import com.smc.domain.model.Message;
import com.smc.domain.model.User;

public class MessageDaoImpl extends HibernateDaoSupport implements MessageDao {

	public void addMessage(String receiverUuid, String senderUuid,
			Message message) {
		Session session = getSession();
		Transaction tx = session.beginTransaction();
		User receiver = (User) session.load(User.class, receiverUuid);
		User sender = (User) session.load(User.class, senderUuid);
		message.setSender(sender);
		message.setReceiver(receiver);
		session.saveOrUpdate(message);
		tx.commit();
	}

}
